package com.ebao.po.blog;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

/**
 * @desc 博客
 * @author snow
 * @date 2012-7-10
 */
@Entity
@Table(name = "T_Blog")
public class TBlog implements Serializable {

	private static final long serialVersionUID = -5522388519106646942L;
	
	private Long id;
	private TBlogClassify blogClassify;		// 博客所属分类
	private boolean isDraft;				// 是否是草稿
	private boolean isAcademic;				// 是否学术性质,学术类的博文将在学术中心模块展示
	private String title;					// 标题
	private String content;					// 内容
	private String createDate;				// 创建日期
	private String lastModifyDate;			// 最近一次修改日期
	private List<TBlogComment> blogComment = new ArrayList<TBlogComment>();	// 博客评论
//	private Set<TArticleAccess> blogAccess = new HashSet<TArticleAccess>();	// 博文访问记录,在Action中根据日期排序转换为List,一个实体类中不能有多个List所以这里用Set
//	private List<TTag> tags = new ArrayList<TTag>();	// 博客标签,单向由TTag到TBlog

	@Id
	@GeneratedValue
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(optional = false, targetEntity = TBlogClassify.class)
	@JoinColumn(name = "blogClassify_id")
	public TBlogClassify getBlogClassify() {
		return blogClassify;
	}

	public void setBlogClassify(TBlogClassify blogClassify) {
		this.blogClassify = blogClassify;
	}

	public boolean isDraft() {
		return isDraft;
	}

	public void setDraft(boolean isDraft) {
		this.isDraft = isDraft;
	}

	public boolean isAcademic() {
		return isAcademic;
	}

	public void setAcademic(boolean isAcademic) {
		this.isAcademic = isAcademic;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Lob
	@Basic(fetch = FetchType.LAZY)
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(length = 19)
	public String getCreateDate() {
		return createDate;
	}

	public void setCreateDate(String createDate) {
		this.createDate = createDate;
	}

	@Column(length = 19)
	public String getLastModifyDate() {
		return lastModifyDate;
	}

	public void setLastModifyDate(String lastModifyDate) {
		this.lastModifyDate = lastModifyDate;
	}

	@OneToMany(cascade = {CascadeType.REMOVE}, mappedBy = "blog", targetEntity = TBlogComment.class)
	@OrderBy(value = "commentDate ASC")
	public List<TBlogComment> getBlogComment() {
		return blogComment;
	}

	public void setBlogComment(List<TBlogComment> blogComment) {
		this.blogComment = blogComment;
	}

}
